﻿Public Class bag_litecad

    Dim Wfrm As Integer, Hfrm As Integer, Hmenu As Integer, hblock As Integer, hmodelblock As Integer
    Dim hLcWnd As Integer, hLcDrw As Integer

    Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            
            Dim hView As Integer
            'Lcad.Initialize("")
            ' register LiteCAD
            Lcad.PropPutStr(0, LC_PROP_G_REGCODE, "12345")
            ' create CAD window and a drawing
            hLcWnd = Lcad.CreateWindow(Handle, LC_WS_DEFAULT, 0, Hmenu, Wfrm, Hfrm - Hmenu)
            Lcad.WndResize(hLcWnd, 0, Hmenu, Wfrm, Hfrm - Hmenu)
            hLcDrw = Lcad.CreateDrawing()
            Lcad.DrwNew(hLcDrw, "", hLcWnd)

            'aggiungi_asola()
            Lcad.DrwRegenViews(hLcDrw, 0)
            WndRedraw(hLcWnd)

            ' hide grid
            hView = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_VIEW_MODEL)
            Lcad.PropPutBool(hView, LC_PROP_VIEW_GRID, False)
            ' Zoom extents
            Lcad.WndExeCommand(hLcWnd, LC_CMD_ZOOM_EXT, 0)
            'Lcad.PropPutBool(hLcDrw, LC_PROP_DRW_READONLY, True)
        Catch ex As Exception
        End Try


    End Sub

    Private Sub UserControl1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Lcad.GetClientSize(Handle, Wfrm, Hfrm)
        If hLcWnd <> 0 Then
            Lcad.WndResize(hLcWnd, 0, 0, Wfrm, Hfrm)
            Lcad.WndRedraw(hLcWnd)
        End If
    End Sub
    ''' <summary>
    ''' aggiungi rettangolo/quadrato
    ''' </summary>
    ''' <param name="x">quota x</param>
    ''' <param name="y">quota y</param>
    ''' <param name="dim1">larghezza utensile</param>
    ''' <param name="dim2"> altezza utensile</param>
    ''' <param name="angolo">angolo colpo</param>
    ''' <remarks></remarks>
    Public Sub aggiungi_rettangolo(ByVal x As Double, ByVal y As Double, ByVal dim1 As Double, ByVal dim2 As Double, ByVal angolo As Double)
        hblock = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
        Lcad.PropPutStr(hLcDrw, LC_PROP_DRW_COLOR, "2")
        Lcad.BlockAddRect(hblock, x, y, dim1, dim2, angolo, 0)

    End Sub
    ''' <summary>
    ''' aggiungi sagoma speciale
    ''' </summary>
    ''' <param name="x">quota x</param>
    ''' <param name="y">quota y</param>
    ''' <param name="angolo">angolo colpo</param>
    ''' <param name="nome_blocco">codice utensile</param>
    ''' <param name="file_dxf"></param>
    ''' <remarks></remarks>
    Public Sub aggiungi_speciale(ByVal x As Double, ByVal y As Double, ByVal angolo As Double, ByVal nome_blocco As String, ByVal file_dxf As String)
        hmodelblock = PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
        hblock = Lcad.DrwAddBlockFromFile(hLcDrw, nome_blocco, file_dxf, LC_BLOCK_OVERWRITEYES, 0)
        BlockAddBlockRef(hmodelblock, hblock, x, y, 1, angolo)
    End Sub
    ''' <summary>
    ''' aggiungi sagoma lamiera
    ''' </summary>
    ''' <param name="x">dimensione x</param>
    ''' <param name="y">dimensione y</param>
    ''' <remarks></remarks>
    Public Sub aggiungi_lamiera(ByVal x As Double, ByVal y As Double)
        hblock = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
        BlockAddRect(hblock, 0, 0, x, y, 0, 0)
    End Sub
    ''' <summary>
    ''' aggiungi tondo
    ''' </summary>
    ''' <param name="x">quota x</param>
    ''' <param name="y">quota y</param>
    ''' <param name="diametro">diametro punzone</param>
    ''' <remarks></remarks>
    Public Sub aggiungi_cerchio(ByVal x As Double, ByVal y As Double, ByVal diametro As Double)
        hblock = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
        Lcad.PropPutStr(hLcDrw, LC_PROP_DRW_COLOR, "1")
        Lcad.BlockAddCircle(hblock, x, y, diametro / 2, 0)
    End Sub

    Public Sub aggiungi_asola()
        Dim hpline As Integer
        hblock = Lcad.PropGetHandle(hLcDrw, LC_PROP_DRW_BLOCK_MODEL)
        Lcad.BlockAddLine(hblock, 0, 0, 20, 0)
        Lcad.BlockAddArc3P(hblock, 20, 0, 30, 10, 20, 20)
        Lcad.BlockAddLine(hblock, 20, 20, 0, 20)
        Lcad.BlockAddArc3P(hblock, 0, 20, -10, 10, 0, 0)
        BlockSelJoin(hblock, 0)
        'Lcad.PlineAddVer2(hpline, 0, 0, 0, 0, 0, 0)
        'Lcad.PlineAddVer2(hpline, 0, 20, 0, 0, 0, 0)
        'Lcad.PlineAddVer2(hpline, 0, 20, 10, 102, 0, 0)
        'Lcad.BlockAddArc(hpline, 20, 10, 5, 0, 180)


        'PlineAddVer(hpline, 0, 0, 0)
        'PlineAddVer(hpline, 0, 20, 0)

    End Sub

    Public Sub aggiorna()
        Lcad.DrwRegenViews(hLcDrw, 0)
        WndRedraw(hLcWnd)
        Lcad.WndExeCommand(hLcWnd, LC_CMD_ZOOM_EXT, 0)
    End Sub
End Class
